<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
	</head>
	<body>
		<!-- 
		<li>0</li>
		<li>1</li>
		<li>2</li>
		-->

		<script>
			console.log('1');
			setTimeout(function() {
				console.log('2');
				// process.nextTick(function() {
				// 	console.log('3');
				// })
				new Promise(function(resolve) {
					console.log('4');
					resolve();
				}).then(function() {
					console.log('5')
				})
			})
			// process.nextTick(function() {
			// 	console.log('6');
			// })
			new Promise(function(resolve) {
				console.log('7');
				resolve();
			}).then(function() {
				console.log('8')
			})

			setTimeout(function() {
				console.log('9');
				// process.nextTick(function() {
				// 	console.log('10');
				// })
				new Promise(function(resolve) {
					console.log('11');
					resolve();
				}).then(function() {
					console.log('12')
				})
			})

			// 1 7 8 2 4 5 9 11 12

			async function async1() {
				console.log("async1 start"); // (2)        
				await async2();
				console.log("async1 end"); // (6)    
			}
			async function async2() {
				console.log('async2'); // (3)     
			}
			console.log("script start"); // (1)      
			setTimeout(function() {
				console.log("settimeout"); // (8)      
			}, 0);
			async1();
			new Promise(function(resolve) {
				console.log("promise1"); // (4)         
				resolve();
			}).then(function() {
				console.log("promise2"); // (7)    
			});
			console.log('script end'); // (5)
		</script>
	</body>
</html>